package com.wythe.mall.adapter;

import android.content.Context;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.wythe.mall.R;
import com.wythe.mall.model.CarBean;
import com.wythe.mall.model.ShopBean;

import java.util.ArrayList;

import top.yokey.base.bean.StoreBuyBean;

/**
 * 适配器
 *
 * @author MapleStory
 * @ qq 1002285057
 * @ project https://gitee.com/MapStory/Shopwt-Android
 */

public class GoodsBuyListAdapter extends RecyclerView.Adapter<GoodsBuyListAdapter.ViewHolder> {

    private final ArrayList<CarBean> arrayList;
    private OnItemClickListener onItemClickListener;
    private Context mContext;

    public GoodsBuyListAdapter(Context context, ArrayList<CarBean> arrayList) {
        mContext = context;
        this.arrayList = arrayList;
        this.onItemClickListener = null;
    }

    @Override
    public int getItemCount() {

        return arrayList.size();

    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        final CarBean bean = arrayList.get(position);
        Glide.with(mContext)
                .load(bean.getIcon())
                .dontAnimate()
                .crossFade()
                .diskCacheStrategy(DiskCacheStrategy.ALL)
                .into(holder.mainImageView);
        holder.nameTextView.setText(bean.getTitle());
        holder.mobileTextView.setText(bean.getSpecs());
        holder.moneyTextView.setText("￥" + bean.getPrice());
        holder.activityTextView.setText(bean.getShop());
        holder.numberTextView.setText("数量："+bean.getCount());
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup group, int viewType) {
        View view = LayoutInflater.from(group.getContext()).inflate(R.layout.item_list_goods_buy, group, false);
        return new ViewHolder(view);
    }

    public void setOnItemClickListener(OnItemClickListener listener) {

        this.onItemClickListener = listener;

    }

    public interface OnItemClickListener {

        void onClick(int position, StoreBuyBean.GoodsListBean bean);

    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private RelativeLayout mainRelativeLayout;
        private AppCompatImageView mainImageView;
        private AppCompatTextView nameTextView;
        private AppCompatTextView moneyTextView;
        private AppCompatTextView numberTextView;
        private AppCompatTextView mobileTextView;
        private AppCompatTextView activityTextView;

        private ViewHolder(View view) {
            super(view);
            mainRelativeLayout = view.findViewById(R.id.mainRelativeLayout);
            mainImageView = view.findViewById(R.id.mainImageView);
            nameTextView = view.findViewById(R.id.nameTextView);
            moneyTextView = view.findViewById(R.id.moneyTextView);
            numberTextView = view.findViewById(R.id.numberTextView);
            mobileTextView = view.findViewById(R.id.mobileTextView);
            activityTextView = view.findViewById(R.id.activityTextView);
        }

    }

}
